/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package snake.core.listeners;

import java.awt.Container;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import javax.swing.JLabel;
import snake.SnakeGame;
import snake.core.PositionToComponentNoConverter;
import snake.core.gameinterface.MainWindow;
import snake.gameplay.Position;
import snake.gameplay.Snake;

/**
 *
 * @author otatarik
 */
public class SnakeKeyListener extends BaseSnakeListener implements KeyListener {

    private Container container;
    private static final Position POSITION_CHANGE_UP = new Position(0, -1);
    private static final Position POSITION_CHANGE_DOWN = new Position(0, 1);
    private static final Position POSITION_CHANGE_LEFT = new Position(-1, 0);
    private static final Position POSITION_CHANGE_RIGTH = new Position(1, 0);

    public SnakeKeyListener() {
    }

    public SnakeKeyListener(Container container, Snake snake) {
        super(snake, container);
    }

    public void keyTyped(KeyEvent e) {
    }

    public void keyPressed(KeyEvent e) {
//        switch (e.getKeyCode()) {
//            case KeyEvent.VK_UP: //(0;-1)
//                snake.setMovementDirection("UP");
//                //changePosition(POSITION_CHANGE_UP);
//                break;
//            case KeyEvent.VK_DOWN: //(0;1)
//                snake.setMovementDirection("DOWN");
//                //changePosition(POSITION_CHANGE_DOWN);
//                break;
//            case KeyEvent.VK_LEFT: //(-1;0)
//                snake.setMovementDirection("LEFT");
//                //changePosition(POSITION_CHANGE_LEFT);
//                break;
//            case KeyEvent.VK_RIGHT: //(1;0)
//                snake.setMovementDirection("RIGTH");
//                //changePosition(POSITION_CHANGE_RIGTH);
//                break;
//            default:
//                ;
//        }

        if (checkTurnAroundMove(e.getKeyCode())) {
            BaseSnakeListener.snake.setMovementDirection(e.getKeyCode());
        }
    }

    public void keyReleased(KeyEvent e) {
    }

    private boolean checkTurnAroundMove(int movement) {
        if (Math.abs(BaseSnakeListener.snake.getMovementDirection() - movement) == 2) {
            return false;
        }
        return true;
    }
}
